package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.FictionBuyDAO;
import com.swlz.entity.FictionBuy;
import com.swlz.exception.CodeException;
import com.swlz.service.FictionBuyService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 小说消费清单
 * ClassName : com.swlz.service.impl.FictionBuyServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-07-01 06:17:24
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class FictionBuyServiceImpl implements FictionBuyService {
	
	private FictionBuyDAO fictionBuyDAO = new FictionBuyDAO();

	@Override
	public int add(FictionBuy fictionBuy) throws CodeException {
		try {
			return fictionBuyDAO.insertSelective(fictionBuy);
		} catch (SQLException e) {
			throw new CodeException(500, "添加小说消费清单错误",e);
		}
	}

	@Override
	public int update(FictionBuy fictionBuy) throws CodeException {
		try {
			return fictionBuyDAO.updateSelective(fictionBuy);
		} catch (SQLException e) {
			throw new CodeException(501, "修改小说消费清单错误",e);
		}
	}

	@Override
	public int delete(Long buyId) throws CodeException {
		try {
			return fictionBuyDAO.deleteById(buyId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除小说消费清单错误",e);
		}
	}

	@Override
	public FictionBuy get(Long buyId) throws CodeException {
		try {
			return fictionBuyDAO.selectById(buyId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取小说消费清单失败",e);
		}
	}

	@Override
	public PageVO<FictionBuy> page(FictionBuy fictionBuy, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = fictionBuyDAO.countByModel(fictionBuy);
			PageVO<FictionBuy> page = new PageVO<>(total, current, rowMax);
			return page.setList(fictionBuyDAO.selectByModel(fictionBuy, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取小说消费清单分页数据失败",e);
		}
	}


}
